package com.STS.ELearning.DAO
{
	/**
	* @author www.comtaste.com
	*/
	
	
	import com.STS.ELearning.VO.KategorilerVO;
	
	import flash.data.SQLConnection;
	import flash.data.SQLStatement;
	import flash.errors.SQLError;
	import flash.events.SQLErrorEvent;
	import flash.events.SQLEvent;
	
	import mx.collections.ArrayCollection;
	import mx.utils.StringUtil;
	
	public class Kategoriler extends BaseDao
	{
	
		
		private static var instance:Kategoriler;
		private static const TABLE_NAME:String="Kategoriler";
		public static function getInstance():Kategoriler {
			if( instance == null )
				instance = new Kategoriler( new SingletonLock );
			return instance;
		}
		
	
		public function Kategoriler( lock: SingletonLock) {
			super(TABLE_NAME);
		}
	
		
		public override function getTableContent(order:String=null,where:String=null,whereParams:Array=null):Array{
			
			var o:String="idUstKategori,sira";
			if(order!=null && StringUtil.trim(order).length>0)
			{
				o=order;
			}
			
			var data:Array=super.getTableContent(o,where,whereParams);
			var arrlist:Array=new Array();
			if(data!=null)
				for each(var item:Object in data)
				{
					arrlist.push( new KategorilerVO(item));
				}
			return arrlist;
		}
		
		public function updateRow( rowItem:Object):Boolean {
			
			var text:String = "UPDATE main."+TABLE_NAME+" SET  ad = @ad, aciklama = @aciklama,"+
				" surec = @surec, otarih = @otarih, dtarih = @dtarih, sira = @sira, idUstKategori = @idUstKategori"+
				" WHERE id =@id ;";
			var params:Array = [ {name:"id", value:rowItem.id}, {name:"ad", value:rowItem.ad}, 
				{name:"aciklama", value:rowItem.aciklama}, {name:"surec", value:rowItem.surec}, 
				{name:"otarih", value:rowItem.otarih}, {name:"dtarih", value:rowItem.dtarih}, 
				{name:"sira", value:rowItem.sira}, {name:"idUstKategori", value:rowItem.idUstKategori} ];
			return executeSingleResult(text,params);
		}
		
		public function insertRow( rowItem:KategorilerVO):Boolean {
			var text:String = 'INSERT INTO main.'+TABLE_NAME+'( id, ad, aciklama, surec, otarih, dtarih, sira, idUstKategori )'+
				' VALUES ( '+getId()+',@ad,@aciklama,@surec,@otarih,@dtarih,@sira,@idUstKategori );';
			var params:Array = [  {name:"ad", value:rowItem.ad}, {name:"aciklama", value:rowItem.aciklama}, 
				{name:"surec", value:rowItem.surec}, {name:"otarih", value:rowItem.otarih},
				{name:"dtarih", value:rowItem.dtarih}, {name:"sira", value:rowItem.sira}, 
				{name:"idUstKategori", value:rowItem.idUstKategori} ];
			return executeSingleResult(text,params,rowItem,"id");
		}
		
		public function deleteRow( rowItem:Object):Boolean {
			
			var text:String = 'DELETE FROM main.'+TABLE_NAME+' WHERE id = @id;';
			var params:Array = [ {name:"id", value:rowItem.id} ];
			return executeSingleResult(text,params);
		}
		
		
	}
}

class SingletonLock {}
